<?php
class AboutController extends default_controllers_Controller
{
	protected function _initSubMenu()
	{
		$subMenu = new Engine_Core_Collection();

		$item = new Engine_Core_Wrapper();
		$item->alias = 'news';
		$item->title = 'Новости';
		$item->isActive = $this->_request->getActionName() == 'news-entry';
		$subMenu->itemAppend($item->alias, $item);

		$item = new Engine_Core_Wrapper();
		$item->alias = 'publications';
		$item->title = 'Публикации';
		$item->isActive = $this->_request->getActionName() == 'publication';
		$subMenu->itemAppend($item->alias, $item);

		$item = new Engine_Core_Wrapper();
		$item->alias = 'contacts';
		$item->title = 'Контакты';
		$subMenu->itemAppend($item->alias, $item);

		foreach($subMenu->items() as $item) {
			$item->url      = $this->view->url(array('alias' => $item->alias, 'controller' => $this->_request->getControllerName()), 'controller-alias');
			$item->isActive = $item->isActive || ($this->_request->getActionName() == $item->alias);
		}

		$this->view->subMenu = $subMenu;
	}

	public function indexAction()
	{
		$this->_request->setParam('alias', 'about');
		
		$this->view->entry      = $this->getEntryByIdOrAlias(core_Divisions::getInstance());
	}

	public function newsAction()
	{
		$this->view->collection = core_News::getInstance()->getCollection(array('paging' => array('page' => $this->_request->getParam('page', 1), 'perPage' => 4)));
	}

	public function newsEntryAction()
	{
		if (!$entry = $this->getEntryByIdOrAlias(core_News::getInstance())) {
			$this->_helper->redirector('news');
		}

		$this->view->entry    = $entry;
		$this->view->next     = core_News::getInstance()->getNextEntry($entry->id);
		$this->view->previous = core_News::getInstance()->getPreviousEntry($entry->id);
	}

	public function publicationsAction()
	{
		$this->view->collection = core_Articles::getInstance()->getCollection(array('paging' => array('page' => $this->_request->getParam('page', 1), 'perPage' => 4)));
	}

	public function publicationAction()
	{
		if (!$entry = $this->getEntryByIdOrAlias(core_Articles::getInstance())) {
			$this->_helper->redirector('articles');
		}

		$this->view->entry      = $entry;
	}

	public function contactsAction()
	{}
}